
OV2640_JPEG_INIT = [
  [ 0xff, b'\x00' ],
  [ 0x2c, b'\xff' ],
  [ 0x2e, b'\xdf' ],
  [ 0xff, b'\x01' ],
  [ 0x3c, b'\x32' ],
  [ 0x11, b'\x04' ],	
  [ 0x09, b'\x02' ],
  [ 0x04, b'\x28' ],
  [ 0x13, b'\xe5' ],
  [ 0x14, b'\x48' ],
  [ 0x2c, b'\x0c' ],
  [ 0x33, b'\x78' ],
  [ 0x3a, b'\x33' ],
  [ 0x3b, b'\xfB' ],
  [ 0x3e, b'\x00' ],
  [ 0x43, b'\x11' ],
  [ 0x16, b'\x10' ],
  [ 0x39, b'\x92' ],
  [ 0x35, b'\xda' ],
  [ 0x22, b'\x1a' ],
  [ 0x37, b'\xc3' ],
  [ 0x23, b'\x00' ],
  [ 0x34, b'\xc0' ],
  [ 0x36, b'\x1a' ],
  [ 0x06, b'\x88' ],
  [ 0x07, b'\xc0' ],
  [ 0x0d, b'\x87' ],
  [ 0x0e, b'\x41' ],
  [ 0x4c, b'\x00' ],
  [ 0x48, b'\x00' ],
  [ 0x5B, b'\x00' ],
  [ 0x42, b'\x03' ],
  [ 0x4a, b'\x81' ],
  [ 0x21, b'\x99' ],
  [ 0x24, b'\x40' ],
  [ 0x25, b'\x38' ],
  [ 0x26, b'\x82' ],
  [ 0x5c, b'\x00' ],
  [ 0x63, b'\x00' ],
  [ 0x61, b'\x70' ],
  [ 0x62, b'\x80' ],
  [ 0x7c, b'\x05' ],
  [ 0x20, b'\x80' ],
  [ 0x28, b'\x30' ],
  [ 0x6c, b'\x00' ],
  [ 0x6d, b'\x80' ],
  [ 0x6e, b'\x00' ],
  [ 0x70, b'\x02' ],
  [ 0x71, b'\x94' ],
  [ 0x73, b'\xc1' ],
  [ 0x12, b'\x40' ],
  [ 0x17, b'\x11' ],
  [ 0x18, b'\x43' ],
  [ 0x19, b'\x00' ],
  [ 0x1a, b'\x4b' ],
  [ 0x32, b'\x09' ],
  [ 0x37, b'\xc0' ],
  [ 0x4f, b'\x60' ],
  [ 0x50, b'\xa8' ],
  [ 0x6d, b'\x00' ],
  [ 0x3d, b'\x38' ],
  [ 0x46, b'\x3f' ],
  [ 0x4f, b'\x60' ],
  [ 0x0c, b'\x3c' ],
  [ 0xff, b'\x00' ],
  [ 0xe5, b'\x7f' ],
  [ 0xf9, b'\xc0' ],
  [ 0x41, b'\x24' ],
  [ 0xe0, b'\x14' ],
  [ 0x76, b'\xff' ],
  [ 0x33, b'\xa0' ],
  [ 0x42, b'\x20' ],
  [ 0x43, b'\x18' ],
  [ 0x4c, b'\x00' ],
  [ 0x87, b'\xd5' ],
  [ 0x88, b'\x3f' ],
  [ 0xd7, b'\x03' ],
  [ 0xd9, b'\x10' ],
  [ 0xd3, b'\x82' ],
  [ 0xc8, b'\x08' ],
  [ 0xc9, b'\x80' ],
  [ 0x7c, b'\x00' ],
  [ 0x7d, b'\x00' ],
  [ 0x7c, b'\x03' ],
  [ 0x7d, b'\x48' ],
  [ 0x7d, b'\x48' ],
  [ 0x7c, b'\x08' ],
  [ 0x7d, b'\x20' ],
  [ 0x7d, b'\x10' ],
  [ 0x7d, b'\x0e' ],
  [ 0x90, b'\x00' ],
  [ 0x91, b'\x0e' ],
  [ 0x91, b'\x1a' ],
  [ 0x91, b'\x31' ],
  [ 0x91, b'\x5a' ],
  [ 0x91, b'\x69' ],
  [ 0x91, b'\x75' ],
  [ 0x91, b'\x7e' ],
  [ 0x91, b'\x88' ],
  [ 0x91, b'\x8f' ],
  [ 0x91, b'\x96' ],
  [ 0x91, b'\xa3' ],
  [ 0x91, b'\xaf' ],
  [ 0x91, b'\xc4' ],
  [ 0x91, b'\xd7' ],
  [ 0x91, b'\xe8' ],
  [ 0x91, b'\x20' ],
  [ 0x92, b'\x00' ],
  [ 0x93, b'\x06' ],
  [ 0x93, b'\xe3' ],
  [ 0x93, b'\x05' ],
  [ 0x93, b'\x05' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x04' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x96, b'\x00' ],
  [ 0x97, b'\x08' ],
  [ 0x97, b'\x19' ],
  [ 0x97, b'\x02' ],
  [ 0x97, b'\x0c' ],
  [ 0x97, b'\x24' ],
  [ 0x97, b'\x30' ],
  [ 0x97, b'\x28' ],
  [ 0x97, b'\x26' ],
  [ 0x97, b'\x02' ],
  [ 0x97, b'\x98' ],
  [ 0x97, b'\x80' ],
  [ 0x97, b'\x00' ],
  [ 0x97, b'\x00' ],
  [ 0xc3, b'\xed' ],
  [ 0xa4, b'\x00' ],
  [ 0xa8, b'\x00' ],
  [ 0xc5, b'\x11' ],
  [ 0xc6, b'\x51' ],
  [ 0xbf, b'\x80' ],
  [ 0xc7, b'\x10' ],
  [ 0xb6, b'\x66' ],
  [ 0xb8, b'\xA5' ],
  [ 0xb7, b'\x64' ],
  [ 0xb9, b'\x7C' ],
  [ 0xb3, b'\xaf' ],
  [ 0xb4, b'\x97' ],
  [ 0xb5, b'\xFF' ],
  [ 0xb0, b'\xC5' ],
  [ 0xb1, b'\x94' ],
  [ 0xb2, b'\x0f' ],
  [ 0xc4, b'\x5c' ],
  [ 0xc0, b'\x64' ],
  [ 0xc1, b'\x4B' ],
  [ 0x8c, b'\x00' ],
  [ 0x86, b'\x3D' ],
  [ 0x50, b'\x00' ],
  [ 0x51, b'\xC8' ],
  [ 0x52, b'\x96' ],
  [ 0x53, b'\x00' ],
  [ 0x54, b'\x00' ],
  [ 0x55, b'\x00' ],
  [ 0x5a, b'\xC8' ],
  [ 0x5b, b'\x96' ],
  [ 0x5c, b'\x00' ],
  [ 0xd3, b'\x00' ],
  [ 0xc3, b'\xed' ],
  [ 0x7f, b'\x00' ],
  [ 0xda, b'\x00' ],
  [ 0xe5, b'\x1f' ],
  [ 0xe1, b'\x67' ],
  [ 0xe0, b'\x00' ],
  [ 0xdd, b'\x7f' ],
  [ 0x05, b'\x00' ],
  [ 0x12, b'\x40' ],
  [ 0xd3, b'\x04' ],
  [ 0xc0, b'\x16' ],
  [ 0xC1, b'\x12' ],
  [ 0x8c, b'\x00' ],
  [ 0x86, b'\x3d' ],
  [ 0x50, b'\x00' ],
  [ 0x51, b'\x2C' ],
  [ 0x52, b'\x24' ],
  [ 0x53, b'\x00' ],
  [ 0x54, b'\x00' ],
  [ 0x55, b'\x00' ],
  [ 0x5A, b'\x2c' ],
  [ 0x5b, b'\x24' ],
  [ 0x5c, b'\x00' ],
  [ 0xff, b'\xff' ]
]

OV2640_QVGA = [
  [ 0xFF, b'\x00' ],
  [ 0x2c, b'\xff' ],
  [ 0x2e, b'\xdf' ],
  [ 0xFF, b'\x01' ],
  [ 0x3c, b'\x32' ],
  [ 0x11, b'\x00' ],
  [ 0x09, b'\x02' ],
  [ 0x04, b'\xa8' ],
  [ 0x13, b'\xe5' ],
  [ 0x14, b'\x48' ],
  [ 0x2c, b'\x0c' ],
  [ 0x33, b'\x78' ],
  [ 0x3a, b'\x33' ],
  [ 0x3b, b'\xfb' ],
  [ 0x3e, b'\x00' ],
  [ 0x43, b'\x11' ],
  [ 0x16, b'\x10' ],
  [ 0x39, b'\x02' ],
  [ 0x35, b'\x88' ],
  [ 0x22, b'\x0a' ],
  [ 0x37, b'\x40' ],
  [ 0x23, b'\x00' ],
  [ 0x34, b'\xa0' ],
  [ 0x06, b'\x02' ],
  [ 0x06, b'\x88' ],
  [ 0x07, b'\xc0' ],
  [ 0x0d, b'\xb7' ],
  [ 0x0e, b'\x01' ],
  [ 0x4c, b'\x00' ],
  [ 0x4a, b'\x81' ],
  [ 0x21, b'\x99' ],
  [ 0x24, b'\x40' ],
  [ 0x25, b'\x38' ],
  [ 0x26, b'\x82' ],
  [ 0x5c, b'\x00' ],
  [ 0x63, b'\x00' ],
  [ 0x46, b'\x22' ],
  [ 0x0c, b'\x3a' ],
  [ 0x5d, b'\x55' ],
  [ 0x5e, b'\x7d' ],
  [ 0x5f, b'\x7d' ],
  [ 0x60, b'\x55' ],
  [ 0x61, b'\x70' ],
  [ 0x62, b'\x80' ],
  [ 0x7c, b'\x05' ],
  [ 0x20, b'\x80' ],
  [ 0x28, b'\x30' ],
  [ 0x6c, b'\x00' ],
  [ 0x6d, b'\x80' ],
  [ 0x6e, b'\x00' ],
  [ 0x70, b'\x02' ],
  [ 0x71, b'\x94' ],
  [ 0x73, b'\xc1' ],
  [ 0x3d, b'\x34' ],
  [ 0x12, b'\x04' ],
  [ 0x5a, b'\x57' ],
  [ 0x4f, b'\xbb' ],
  [ 0x50, b'\x9c' ],
  [ 0xFF, b'\x00' ],
  [ 0xe5, b'\x7f' ],
  [ 0xf9, b'\xc0' ],
  [ 0x41, b'\x24' ],
  [ 0xe0, b'\x14' ],
  [ 0x76, b'\xff' ],
  [ 0x33, b'\xa0' ],
  [ 0x42, b'\x20' ],
  [ 0x43, b'\x18' ],
  [ 0x4c, b'\x00' ],
  [ 0x87, b'\xd0' ],
  [ 0x88, b'\x3f' ],
  [ 0xd7, b'\x03' ],
  [ 0xd9, b'\x10' ],
  [ 0xd3, b'\x82' ],
  [ 0xc8, b'\x08' ],
  [ 0xc9, b'\x80' ],
  [ 0x7c, b'\x00' ],
  [ 0x7d, b'\x00' ],
  [ 0x7c, b'\x03' ],
  [ 0x7d, b'\x48' ],
  [ 0x7d, b'\x48' ],
  [ 0x7c, b'\x08' ],
  [ 0x7d, b'\x20' ],
  [ 0x7d, b'\x10' ],
  [ 0x7d, b'\x0e' ],
  [ 0x90, b'\x00' ],
  [ 0x91, b'\x0e' ],
  [ 0x91, b'\x1a' ],
  [ 0x91, b'\x31' ],
  [ 0x91, b'\x5a' ],
  [ 0x91, b'\x69' ],
  [ 0x91, b'\x75' ],
  [ 0x91, b'\x7e' ],
  [ 0x91, b'\x88' ],
  [ 0x91, b'\x8f' ],
  [ 0x91, b'\x96' ],
  [ 0x91, b'\xa3' ],
  [ 0x91, b'\xaf' ],
  [ 0x91, b'\xc4' ],
  [ 0x91, b'\xd7' ],
  [ 0x91, b'\xe8' ],
  [ 0x91, b'\x20' ],
  [ 0x92, b'\x00' ],
  [ 0x93, b'\x60' ],
  [ 0x93, b'\xe3' ],
  [ 0x93, b'\x03' ],
  [ 0x93, b'\x03' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x02' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x93, b'\x00' ],
  [ 0x96, b'\x00' ],
  [ 0x97, b'\x08' ],
  [ 0x97, b'\x19' ],
  [ 0x97, b'\x02' ],
  [ 0x97, b'\x0c' ],
  [ 0x97, b'\x24' ],
  [ 0x97, b'\x30' ],
  [ 0x97, b'\x28' ],
  [ 0x97, b'\x26' ],
  [ 0x97, b'\x02' ],
  [ 0x97, b'\x98' ],
  [ 0x97, b'\x80' ],
  [ 0x97, b'\x00' ],
  [ 0x97, b'\x00' ],
  [ 0xa4, b'\x00' ],
  [ 0xa8, b'\x00' ],
  [ 0xc5, b'\x11' ],
  [ 0xc6, b'\x51' ],
  [ 0xbf, b'\x80' ],
  [ 0xc7, b'\x10' ],
  [ 0xb6, b'\x66' ],
  [ 0xb8, b'\xa5' ],
  [ 0xb7, b'\x64' ],
  [ 0xb9, b'\x7c' ],
  [ 0xb3, b'\xaf' ],
  [ 0xb4, b'\x97' ],
  [ 0xb5, b'\xff' ],
  [ 0xb0, b'\xc5' ],
  [ 0xb1, b'\x94' ],
  [ 0xb2, b'\x0f' ],
  [ 0xc4, b'\x5c' ],
  [ 0xa6, b'\x00' ],
  [ 0xa7, b'\x20' ],
  [ 0xa7, b'\xd8' ],
  [ 0xa7, b'\x1b' ],
  [ 0xa7, b'\x31' ],
  [ 0xa7, b'\x00' ],
  [ 0xa7, b'\x18' ],
  [ 0xa7, b'\x20' ],
  [ 0xa7, b'\xd8' ],
  [ 0xa7, b'\x19' ],
  [ 0xa7, b'\x31' ],
  [ 0xa7, b'\x00' ],
  [ 0xa7, b'\x18' ],
  [ 0xa7, b'\x20' ],
  [ 0xa7, b'\xd8' ],
  [ 0xa7, b'\x19' ],
  [ 0xa7, b'\x31' ],
  [ 0xa7, b'\x00' ],
  [ 0xa7, b'\x18' ],
  [ 0x7f, b'\x00' ],
  [ 0xe5, b'\x1f' ],
  [ 0xe1, b'\x77' ],
  [ 0xdd, b'\x7f' ],
  [ 0xc2, b'\x0e' ],
  [ 0xFF, b'\x00' ],
  [ 0xe0, b'\x04' ],
  [ 0xc0, b'\xc8' ],
  [ 0xc1, b'\x96' ],
  [ 0x86, b'\x3d' ],
  [ 0x51, b'\x90' ],
  [ 0x52, b'\x2c' ],
  [ 0x53, b'\x00' ],
  [ 0x54, b'\x00' ],
  [ 0x55, b'\x88' ],
  [ 0x57, b'\x00' ],
  [ 0x50, b'\x92' ],
  [ 0x5a, b'\x50' ],
  [ 0x5b, b'\x3c' ],
  [ 0x5c, b'\x00' ],
  [ 0xd3, b'\x04' ],
  [ 0xe0, b'\x00' ],
  [ 0xFF, b'\x00' ],
  [ 0x05, b'\x00' ],
  [ 0xda, b'\x08' ],
  [ 0xd7, b'\x03' ],
  [ 0xe0, b'\x00' ],
  [ 0x05, b'\x00' ]
]

OV2640_YUV422 = [
  [ 0xFF, b'\x00' ],
  [ 0x05, b'\x00' ],
  [ 0xDA, b'\x10' ],
  [ 0xD7, b'\x03' ],
  [ 0xDF, b'\x00' ],
  [ 0x33, b'\x80' ],
  [ 0x3C, b'\x40' ],
  [ 0xe1, b'\x77' ],
  [ 0x00, b'\x00' ],
  [ 0xff, b'\xff' ]
]

OV2640_RGB565 = [
  [ 0xFF, b'\x00' ],
  [ 0x05, b'\x00' ],
  [ 0xDA, b'\x08' ],
  [ 0x98, b'\x00' ], 
  [ 0x99, b'\x00' ],
  [ 0x00, b'\x00' ]
] 

OV2640_JPEG = [
  [ 0xe0, b'\x14' ],
  [ 0xe1, b'\x77' ],
  [ 0xe5, b'\x1f' ],
  [ 0xd7, b'\x03' ],
  [ 0xda, b'\x10' ],
  [ 0xe0, b'\x00' ],
  [ 0xFF, b'\x01' ],
  [ 0x04, b'\x08' ],
  [ 0xff, b'\xff' ]
]

SENSORADDR = 0x30
PICBUFSIZE = 128